<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix" style="text-align: left;">
      <span>{{role == 3 ? "我的考勤" :"考勤信息"}}</span>
    </div>
    <div style="display: flex;align-items: center;margin-bottom:10px" v-if="role != 3">
      <el-input
        style="width: 250px;margin-right: 10px;"
        placeholder="请输入课程名称"
        v-model="name"
        clearable
      ></el-input>
      <el-button type="primary" @click="query">查询</el-button>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="course.course.courseNo" label="课程号"></el-table-column>
      <el-table-column prop="course.course.name" label="课程名"></el-table-column>
      <el-table-column prop="course.course.teacher.realName" label="授课教师"></el-table-column>
      <el-table-column prop="course.student.name" label="学生"></el-table-column>
      <el-table-column prop="time" label="打卡时间">
      </el-table-column>
    </el-table>
    <el-pagination
      style="text-align:left;margin-top:25px"
      background
      layout="prev, pager, next"
      :total="totalCount"
      @current-change="getPage"
    ></el-pagination>
  </el-card>
</template>

<script>
import { request } from "../request.js";
export default {
  name: "kaoqin",
  data() {
    return {
      name: "",
      role: localStorage.getItem("role"),
      tableData: [],
      pageNo: 1,
      pageSize: 10,
      totalCount: 0,
    };
  },

  created() {
    this.getData();
  },
  methods: {
    /**
     * 查询
     */
    query() {
      this.pageNo = 1;
      this.getData();
    },

    /**
     * 获取分页数据
     */
    getData() {
      let param = {
        name: this.name,
        pageNo: this.pageNo,
        pageSize: this.pageSize
      };

      request
        .request("/kaoqin/getKaoQinList", "POST", param, this)
        .then(data => {
          data = data.data;
          this.tableData = data.list;
          this.pageNo = data.page.currentPage;
          this.totalPage = data.page.totalCount;
        });
    },

    /**
     * 分页器翻页
     */
    getPage(page) {
      this.pageNo = page;
      this.getData();
    },
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
